package com.lzw.blog.admin.controller;

import com.lzw.blog.admin.model.params.PageParam;
import com.lzw.blog.admin.pojo.Permission;
import com.lzw.blog.admin.pojo.Role;
import com.lzw.blog.admin.service.PermissionService;
import com.lzw.blog.admin.service.RoleService;
import com.lzw.blog.admin.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private PermissionService permissionService;
    @PostMapping("roleList")
    public Result listRole(@RequestBody PageParam pageParam) {
        return roleService.listRole(pageParam);
    }

    @GetMapping("/deletePermissionByRoleId/{roleId}")
    public Result deletePermission(@PathVariable Long roleId, @RequestParam Long permissionId) {

        return roleService.deletePermissionByRoleId(roleId, permissionId);

    }

    // 获得所有权限
    @GetMapping("getAllPermissions")
    public Result getAllPermissions(){
        return permissionService.getAllPermissions();
    }

    /*
    为某角色授权
     */
    @GetMapping("setPermissionForRole/{roleId}")
    public Result setPermissionForRole(@PathVariable Long roleId, @RequestParam Long permissionId) {
        return roleService.setPermissionForRole(roleId, permissionId);
    }
    @PostMapping("add")
    public Result addRole(@RequestBody Role role) {
        return roleService.add(role);
    }

    @PostMapping("update")
    public Result updateRole(@RequestBody Role role) {
        return roleService.update(role);
    }
    @GetMapping("delete/{id}")
    public Result deleteRole(@PathVariable("id") Long id) {return roleService.delete(id);}


}
